﻿using System;
using System.Collections.Generic;
//using Wizard.Compiler.Parsers;
//using Wizard.Runtime;


namespace Wizard.Source
{
    public interface IMethodSource
    {
        IWizardEngine Engine { get; }
        IMethodParameterCollection Parameters { get; }
        IBlockSource MainBlock { get; }
        object GetStatementByName(string name);
        IStatementSource MainStatement { get; }
        IStatementSource CreateMainStatement();
    }

//    public class MethodSource : StatementSource
//    {
//        public readonly IWizardEngine Engine;
//        internal IDictionary<string, Object> mIdentifiers;
//        private IBlockSource mMainBlock;

//        public readonly IClassSource Class;

//        private readonly int mId;
//        private readonly string mName;
//        private bool mLoaded;
////        private List<StatementSource> mMethodLines;

//        internal MethodSource(IClassSource source, string name)
//        {
//            Class = source;
//            mName = name;

//            Parameters=new MethodParameterCollection(this);
        
//            Engine = source.Application.Engine;
//            //if (!Application.StatementInfos.TryGetValue("MethodInstance", out mStatementInfo))
//            //    throw new SourceException("Internal Error, SourceInstance class not found.");
//            mIdentifiers = new Dictionary<string, Object>(StringComparer.OrdinalIgnoreCase);
//            mMainBlock = new IBlockSource(this);
//        }

//        public IBlockSource MainBlock
//        {
//            get { return mMainBlock; }
//        }

//        public override MethodSource Source
//        {
//            get { return this; }
//        }

//        public StatementSource GetStatementByName(string statementName)
//        {
//            Object result;
//            if (statementName != null)
//            {
//                mIdentifiers.TryGetValue(statementName, out result);
//                if (result is StatementSource) return (StatementSource) result;
//            }
//            return null;
//        }

//        public BlockVariable GetVariableByName(string varName)
//        {
//            Object result;
//            mIdentifiers.TryGetValue(varName, out result);
//            if (result is BlockVariable) return (BlockVariable) result;
//            return null;
//        }
 
//        public MethodSource(IWizardEngine engine, string methodName, int id)
//        {
//            Engine = engine;
//            mName = methodName;
//            mId = id;
//        }

//        public string Name
//        {
//            get { return mName; }
//        }

//        public int Id
//        {
//            get { return mId; }
//        }
       
//        internal StatementSource GetMethodLine(int pc)
//        {
//            CheckLoaded();
//            return mMainBlock.GetStatement(pc);
//        }

//        private void CheckLoaded()
//        {
//            if (mLoaded) return;
//            //mMethodLines = new List<StatementSource>();
//            //mMethodLines.Add(new StatementSource("InputString",
//            //                                new[]
//            //                                    {"Text", "What is your name", "Value", "<Please enter your name here>"}));
//            //mMethodLines.Add(new StatementSource("Message", new[] {"Text", "Hello"}));
//            //mMethodLines.Add(new StatementSource("Message", new[] {"Text", "World"}));
//            //mMethodLines.Add(new StatementSource("Message", new[] {"Text", "3..."}));
//            //mMethodLines.Add(new StatementSource("Message", new[] {"Text", "4..."}));
//            //mMethodLines.Add(new StatementSource("Message", new[] {"Text", "5..."}));
//            //mMethodLines.Add(new StatementSource("Message", new[] {"Text", "6..."}));
//            //mMethodLines.Add(new StatementSource("Message", new[] {"Text", "7..."}));
//            //mMethodLines.Add(new StatementSource("Message", new[] {"Text", "8 the end"}));
//            mLoaded = true;
//        }

//        public MethodInvoker NewMethodInvoker()
//        {
//            return new MethodInvoker(this);
//        }
//    }

//    public class MethodSourceCollection
//    {
//        private IClassSource mClassSource;
//        private Dictionary<string, MethodSource> mMethodSources;

//        internal MethodSourceCollection(IClassSource classSource)
//        {
//            mMethodSources = new Dictionary<string, MethodSource>(System.StringComparer.OrdinalIgnoreCase);
//            mClassSource = classSource;
//        }

//        public bool TryGetValue(string methodName, out MethodSource value)
//        {
//            return mMethodSources.TryGetValue(methodName, out value);
//        }

//        public MethodSource Add(string className)
//        {
//            MethodSource result = new MethodSource(mClassSource, className);
//            mMethodSources.Add(className, result);
//            return result;
//        }
//    }
}
